package com.fruit.service.user.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fruit.mapper.user.SysRoleMapper;
import com.fruit.pojo.role.SysRole;
import com.fruit.pojo.user.SysWapMenu;
import com.fruit.service.user.SysRoleManager;

@Service("sysRoleService")
public class SysRoleService implements SysRoleManager{

	@Autowired
	private SysRoleMapper sysRoleMapper;
	
	@Override
	public List<SysWapMenu> getUserWapMenu(String roleId) {
		if ("1".equals(roleId)) {
			Map<String, String> params = new HashMap<String, String>();
			params.put("menuState", "01");
			return sysRoleMapper.listAllWapMenu(params);
		}else{
			Map<String, String> params = new HashMap<String, String>();
			params.put("menuState", "01");
			params.put("roleId", roleId);
			return sysRoleMapper.listWapMenuByRole(params);
		}
	}

	@Override
	public Map<String, String> getUserBtnRoleQxname(String roleId, String type, String btnType) {
		Map<String, String> qxMap = new HashMap<String, String>();
		List<String> buttonQXnamelist = null;
		if ("1".equals(roleId)) {
			Map<String, String> params = new HashMap<String, String>();
			params.put("type", type);
			params.put("btnType", btnType);
			buttonQXnamelist = sysRoleMapper.listAllBtnQxName(params); // admin用户拥有所有按钮权限
		} else {
			Map<String, String> params = new HashMap<String, String>();
			params.put("roleId", roleId);
			params.put("type", type);
			params.put("btnType", btnType);
			buttonQXnamelist = sysRoleMapper.listAllBtnRoleQxName(params); // 此角色拥有的按钮权限标识列表
		}
		if(buttonQXnamelist != null){
		for(String qxName:buttonQXnamelist){
			qxMap.put(qxName, "1");
		}
		}
		return qxMap;
	}

	@Override
	public boolean getQxNameCnt(String roleId, String qxName) {
		int cnt = 0;
		if ("1".equals(roleId)) {
			cnt = 1; // admin用户拥有所有按钮权限
		} else {
			Map<String, String> params = new HashMap<String, String>();
			params.put("roleId", roleId);
			params.put("qxName", qxName);
			cnt = sysRoleMapper.qxNameCnt(params); // 此角色拥有的按钮权限标识列表
		}
		
		return (cnt == 1);
	}

	@Override
	public SysRole getRoleInfo(String roleId) {
		return sysRoleMapper.getRoleInfo(roleId);
	}

	
	
	
	
}
